import random

shop = [('香蕉',3),('卫龙辣条',2),('苹果',5),('车厘子',15),('哈根达斯',99),('麒麟西瓜',3)]
#初始化余额
money = 0
coupon = random.randint(1,6)
coupon_name_num = coupon - 1
coupon_name = shop[coupon_name_num][0]
mycart = []
a = b = c = d = e = f = 0

while True:
    money= input("请输入您的银行卡余额：")
    if money.isdigit():
        money = int(money)
        break
    else:
        print("余额非法，重新输入！")





print('---------------------------')
print('欢迎来到小羊购物系统')
print('---------------------------')
print('我们的商品有：')
for key,value in enumerate(shop):  # enumerate 枚举
    print(key,value)
print('---------------------------')
print('您好，我们现在正在进行优惠活动，我们随机送您的:', coupon_name,'7.5折优惠券，请您收好')
print('---------------------------')


while True:
    chose = input("请输入您想要商品的编号：")
    #    0~5     a a@#$#%$ 非法      qQ退出
    if chose.isdigit():
        chose = int(chose)
        if chose > len(shop):  # len()
            print("对不起，没这个商品！")
        elif chose == coupon_name_num:
            print('是否使用优惠券：')
            u = input('使用优惠券输入h,不使用输入j:')
            if u == 'h':
                mycart.append(shop[chose])
                money = money - shop[chose][1] * 0.75
                print("此商品您使用了优惠券，您的余额为：￥", money)
            elif u == 'j':
                money = money - shop[chose][1]
                print("恭喜你，您的余额为：￥", money)
            else:
                print('输入有误，请重新输入！！')
        else:
            if money >= shop[chose][1]:
                mycart.append(shop[chose])
                money = money - shop[chose][1]
                print("恭喜，添加成功！您的余额为：￥",money)

            else:
                print("余额不足，请购买其他商品！")
                if chose == 0:
                    a = a - 1
                elif chose == 1:
                    b = b - 1
                elif chose == 2:
                    c = c - 1
                elif chose == 3:
                    d = d + -1
                elif chose == 4:
                    e = e - 1
                else:
                    f = f - 1

    elif chose == "Q" or chose == "q":
        print("拜拜！")
        break
    else:
        print("输入非法，请重新输入！")
    if chose == 0:
        a = a + 1
    elif chose == 1:
        b = b + 1
    elif chose == 2:
        c = c + 1
    elif chose == 3:
        d = d + 1
    elif chose == 4:
        e = e + 1
    else:
        f = f + 1
g=shop[0]
k=shop[1]
l=shop[2]
m=shop[3]
n=shop[4]
o=shop[5]
# 打印购物小条
print("以下是您的购物小条，请拿好！")
print("--------------------------")
if a!=0:
    print(g,'×',a)
if b!=0:
    print(k,'×',b)
if c!=0:
    print(l,'×',c)
if d!=0:
    print(m,'×',d)
if e!=0:
    print(n,'×',e)
if f!=0:
    print(o,'×',f)
import datetime
time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(time)
print("--------------------------")
print("您的最终余额还剩：￥",money)




